﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="GridList.aspx.cs" Inherits="WebUI_Shop_GridList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <table id="tblContent" cellpadding="5" cellspacing="0" border="1" style="border-collapse: collapse;
        line-height: 22px;">
        <thead style="background-color: Silver">
            <tr>
                <th>
                    ID
                </th>
                <th>
                    Name
                </th>
                <th>
                    Value
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
            </tr>
        </tbody>
    </table>
    <div style="line-height：30px; margin-top: 10px;">
        <label id="lblPageNum">
            1</label>
        <input type="text" value="1" />
        <input type="button" value="转到" onclick="gotoPageNum($(this).prev().val())" />
        <input type="button" value="上一页" onclick="prevPage();" />
        <input type="button" value="下一页" onclick="nextPage();" />
    </div>
    <div style="line-height：30px; margin-top: 10px; color: red;" id="divMsg">
    </div>
    <script type="text/javascript">
        function prevPage() {
            var num = parseInt($('#lblPageNum').text(), 10) - 1;
            gotoPageNum(num);
        }
        function nextPage() {
            var num = parseInt($('#lblPageNum').text(), 10) + 1;
            gotoPageNum(num);
        }
        function gotoPageNum(num) {
            num = parseInt(num, 10);
            if (num > 0) {
                ASP.webui_shop_gridlist_aspx.GetDataSource(num, function (res) {
                    if (res.value) {
                        if (res.value.Rows.length == 0) {
                            showMsg("不存在第 " + num + " 页!");
                        }
                        else {
                            showList(res.value);
                            $("#lblPageNum").html(num);
                        }
                    }
                    else {
                        showMsg("跳转失败");
                    }
                });
            }
            else {
                showMsg("不存在第 " + num + " 页!");
            }

        }
        
        function showList(dataTable) {
            var tBody = $("#tblContent").children("tbody").html("");
            var sb = new StringBuilder();
            for (var i = 0; i < dataTable.Rows.length; i++) {
                sb.appendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>",
                dataTable.Rows[i].ID, dataTable.Rows[i].Name, dataTable.Rows[i].Value);
            }
            tBody.html(sb.toString());
        }

        function showMsg(msg) {
            $("#divMsg").html(msg);
        }

        gotoPageNum(1);
    </script>
</asp:Content>
